package com.scorpio.common.core.page;

public class PageBean {
    /**
     * 当前记录起始索引
     */
    private Integer offset;

    /**
     * 每页显示记录数
     */
    private Integer limit;

    public void setPage() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        setPage(pageDomain);
    }

    public void setPage(PageDomain pageDomain) {
        setOffset((pageDomain.getPageNum() - 1) * pageDomain.getPageSize());
        setLimit(pageDomain.getPageSize());
    }

    public Integer getOffset() {
        if (offset == null || offset < 0) offset = 0;
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
        if (this.offset == null || this.offset < 0) this.offset = 0;
    }

    public Integer getLimit() {
        if (limit == null || limit < 0) limit = 50;
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
        if (this.limit == null || this.limit < 0) this.limit = 50;
    }
}
